import random
from random import shuffle
#调用random函数用于洗牌

#游戏开始阶段：先获取一副完整的牌（108）张，
def game_players():
    players = int(input('请输入玩游戏的人数，4-12\n'))
    return players
#返回多少玩家

def empty_list(num):
    empty_list = [[] for x in range(0,num)]
    return empty_list
#有多少个玩家，返回一个列表，包括多少个玩家数的空列表

def player_names_list(num):
    letter_names = [chr(one) for one in range(97,97+num)]
    namelist = []
    for x in range(0,len(letter_names)):
        playername = '玩家' + letter_names[x]
        namelist.append(playername)
    return namelist
#返回一个列表，从a开始数num个字母，为玩家代称,标记为“玩家#”

def wash_card(lists):
    shuffle(lists) #对于输入的列表牌进行乱序洗牌处理
    return lists #返回洗牌后的结果
#洗牌

def get_apair_card(): #定义四个颜色用于确定颜色种类
    one_color_card = ['0'] + ['1', '2', '3', '4', '5', '6', '7', '8', '9','+2', '↑↓', '⊘']*2 #获得每种颜色的全部牌型
    else_card_1 = ['变色','变色+4'] #定义特殊功能牌
    red,yellow,blue,green = [],[],[],[] #设置各个颜色的空列表
    for x in range(0, 25):
        red_card = '红' + one_color_card[x]
        red.append(red_card)
        yellow_card = '黄' + one_color_card[x]
        yellow.append(yellow_card)
        blue_card = '蓝' + one_color_card[x]
        blue.append(blue_card)
        green_card = '绿' + one_color_card[x]
        green.append(green_card)
    #for循环获取有颜色的全部卡牌
    all_deck_card = red+yellow+blue+green+else_card_1*4
    #所用牌型相加获得完整的一副牌
    return all_deck_card
#返回一副牌为列表

def opnum(peonum): #定义一个开始时如何发牌
    b = []
    opcard = random.choice([6,7,8])
    for i in range(0,peonum):
        a = list_card[:opcard]
        #将洗好的牌从第一张开始发，发opcard张，将所发的牌赋值给a
        del list_card[:opcard]
        #将已经发的牌从牌库中删去
        b.append(a)
        #将a中的列表添加到b的空列表中
        #重复以上过程，形最终在b中形成各位玩家起始的手牌
    return b, list_card
#返回各位玩家起始手牌和牌库剩余卡牌为元组
def card_op_give(cuple):
    return cuple[0]
#获取opnum返回的元组第一个值，即各位玩家开始手牌
def card_op_rest(cuple):
    return cuple[1]
#获取opnum返回的元组第二个值，即牌库剩余的卡牌




if __name__ == '__main__':
    try:
        list_card = wash_card(get_apair_card()*2)
        num = game_players()
        cuple_cards = opnum(num)
        player_names = player_names_list(num)
        player_begin_cards = card_op_give(cuple_cards)
        player_card_dict = dict(zip(player_names, player_begin_cards))
        rest_card_list = card_op_rest(cuple_cards)
        for i in range(0,num):
            yar = player_names[i]
            print(yar,':  ',player_card_dict[yar])
        print(player_card_dict, '\n', '\n', rest_card_list)
    except:
        print('error')
    else:
        pass